package org.example.controller;

import com.google.common.collect.ImmutableMap;
import org.example.entity.SpecValue;
import org.example.model.PageBean;
import org.example.service.SpecValueService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/spe")
public class SpecValueController {
    @Resource
    private SpecValueService specValueService;


    @GetMapping("/list")
    public PageBean<SpecValue> specKeyList(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "5") Integer size,
                                            Integer id){
        return specValueService.specValueList(page,size,id);
    }

    @PostMapping
    public Map<String ,Object> addSpecValue(@RequestBody SpecValue specValue){
        specValueService.addSpecValue(specValue);
        return ImmutableMap.of("code", 1, "msg", "success");
    }

    @GetMapping("/{id}")
    public SpecValue getSpecValueById(@PathVariable("id") Integer id){
        return specValueService.getspecvalue(id);
    }

    @PutMapping
    public Map<String, Object> edit(@RequestBody SpecValue specValue) {
        specValueService.editSpecValue(specValue);
        return ImmutableMap.of("code", 1, "msg", "success");
    }

    @DeleteMapping("/{id}")
    public Map<String ,Object> deleteSpecValue(@PathVariable("id") Integer id){
        specValueService.deleteSpecValue(id);
        return ImmutableMap.of("code", 1, "msg", "success");
    }
}
